/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.common.util;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.criterion.SimpleExpression;
import org.hibernate.criterion.Criterion;

/**
 * Expresion a ser usada para hacer busquedas.<br>
 * 
 * @author nicolas.gonzalez
 */
public class ExpressionObj {

    private String property;
    private Object value;
    private final ExpressionOperator operator;
    
    /**
     * @return Devuelve un {@link SimpleExpression}
     */
    public Criterion asSimpleExpression() {
        return operator.asSimpleExpression(this.property, this.value);
    }
    
    
    /**
     * El operador por defecto es: {@link ExpressionOperator#Equals}
     */
    public ExpressionObj() {
        this.operator = ExpressionOperator.Equals;
    }
    
    /**
     * El operador por defecto es: {@link ExpressionOperator#Equals}
     * @param property
     * @param Value
     */
    public ExpressionObj(String property, Object value) {
        this.property = property;
        this.value = value;
        this.operator = ExpressionOperator.Equals;
    }
    
    /**
     * @param property
     * @param Value
     */
    public ExpressionObj(String property, Object value, ExpressionOperator operator) {
        this.property = property;
        this.value = value;
        this.operator = operator;
    }

    /**
     * @return the property
     */
    public String getProperty() {
        return this.property;
    }

    /**
     * @param property the property to set
     */
    public void setProperty(String property) {
        this.property = property;
    }

    /**
     * @return the value
     */
    public Object getValue() {
        return this.value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(Object value) {
        this.value = value;
    }

    /**
     * @return the operator
     */
    public ExpressionOperator getOperator() {
        return this.operator;
    }

    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE);
    }
    
}
